package com.store.practice.controller;

import com.store.practice.common.api.CommonResult;
import com.store.practice.dto.BgStaffInsertParam;
import com.store.practice.model.BgStaff;
import com.store.practice.service.BgStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "BgStaffController",description = "人员管理")
@RequestMapping("/bgStaff")
public class BgStaffController {
    @Autowired
    private BgStaffService staffService;

    @ApiOperation("新增人员信息")
    @PostMapping("/insert")
    public CommonResult insert(@RequestBody BgStaffInsertParam param){
        int i = staffService.insert(param);
        if (i>0) {
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除人员")
    @PostMapping("/delete")
    public CommonResult delete(Integer id){
        int i = staffService.delete(id);
        if (i>0) {
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }

    @ApiOperation("编辑人员信息")
    @PostMapping("/update")
    public CommonResult update(Integer id,@RequestBody BgStaffInsertParam param){
        int i = staffService.update(id, param);
        if (i>0) {
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }

    @ApiOperation("展示人员列表")
    @GetMapping("/list")
    public CommonResult list(){
        List<BgStaff> list = staffService.list();
        return CommonResult.success(list);
    }
}
